/*
Copyright (C) 2009-2010 Xanadu Development Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#pragma once

#include <hash_map>

using namespace std;
using namespace stdext;

class MapMobs;
class MapNPCs;
class MapPlayers;
class MapPortalData;
class MapDrops;
class MapReactors;
class Drop;
class Reactor;
class NPC;
class Mob;
class PacketWriter;
class PlayerShop;
class Player;
class PvP;
class Event;
class Channel;
class MapShipData;
struct Position;

class Map {
private:
	int id, type;
	bool spawn, ship;
	string music;
	MapMobs* mobs;
	MapPlayers* players;
	MapNPCs* npcs;
	MapDrops* drops;
	MapReactors* reactors;
	MapShipData* shipData;
	Event* mevent;
	Channel* channel;
	PvP* pvp;
	hash_map <string, MapPortalData*> portals;
	hash_map <int, PlayerShop *> playershops;
public:
	Map(Channel* channel, int id);
	int getID() {
		return id;
	}
	MapPlayers* getPlayers() {
		return players;
	}
	MapMobs* getMobs() {
		return mobs;
	}
	MapNPCs* getNPCs() {
		return npcs;
	}
	MapReactors* getReactors() {
		return reactors;
	}
	MapDrops* getDrops() {
		return drops;
	}
	MapPortalData* getPortal(string name) {
		return portals[name];
	}
	MapPortalData* getPortal(int pid);
	Position getPortalPosition(int pid);
	Drop* getDrop(int id);
	Mob* getMob(int id);
	NPC* getNPC(int id);
	Player* getPlayer(int id);
	Reactor* getReactor(int id);
	void runTimer();
	void addPlayer(Player* player);
	void removePlayer(Player* player);
	void send(PacketWriter* pw);
	void send(PacketWriter* pw, Player* player);
	void send(PacketWriter* pw, Player* player, Position pos);
	int getReturnMap();
	Mob* spawnMob(int id, int x, int y);
	Reactor* spawnReactor(int id, int x, int y);
	void killMob(Mob* mob);
	void destroyReactor(Reactor* reactor);
	int getMobsCount();
	Reactor* getReactorByReactorID(int id);
	void setSpawn(bool spawn);
	bool getSpawn() {
		return spawn;
	}
	void clearReactors();
	void clearDrops();
	void clearMobs();
	void clear();
	int getClosestSpawnPos(Position pos);
	Position findFoothold(Position pos, int* fh = NULL);
	void startPvP();
	void stopPvP();
	void showMessage(string& msg);
	void playSound(string& name);
	void showEffect(string& name);
	void showObject(string& name);
	void changeMusic(string& name);
	string& getMusic() {
		return music;
	}
	PvP* getPvP(){
		return pvp;
	}
	Event* getEvent() {
		return mevent;
	}
	Channel* getChannel() {
		return channel;
	}
	void setEvent(Event* e);
	int getType(){
		return type;
	}
	bool getShip(){
		return ship;
	}
	void setShip(bool s);
	// PlayerShops
	void addPlayerShop(PlayerShop *shop);
	void removePlayerShop(int id);
	PlayerShop* getPlayerShop(int id);
};


